using Magiq.Behaviors;
using Magiq.Delete;

namespace Magiq.Objects
{
    public class DeleteStrategy<T> : BehaviorHandler<IObjectsDeleteBehavior>, IDeleteStrategy where T : class
    {
        public DeleteStrategy(IDelete<T> delete) : base(delete.Behavior)
        {
            this.delete = delete;
            Default<DefaultObjectsBehavior>();
        }

        public int Execute()
        {
            var source = Call(x => x.FindSourceOf(delete.Source));
            return Call(x => x.RemoveItems(delete.Source, source));
        }

        private readonly IDelete<T> delete;
    }
}